<?php

namespace App\Models\Kms\Attendance;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;

class AttendanceDailyPointTraceModel extends BaseModel
{
    protected $table = "attendance_daily_point_trace";

    const GPS_SWITCH_ON   = 1;
    const GPS_SWITCH_OFF  = 0;
    const GPS_SWITCH_TEXT = [
        self::GPS_SWITCH_ON  => "开启",
        self::GPS_SWITCH_OFF => "关闭"
    ];

    const  CELLULAR_NETWORK_SWITCH_ON   = 1;
    const  CELLULAR_NETWORK_SWITCH_OFF  = 0;
    const  CELLULAR_NETWORK_SWITCH_TEXT = [
        self::CELLULAR_NETWORK_SWITCH_ON  => "开启",
        self::CELLULAR_NETWORK_SWITCH_OFF => "关闭"
    ];

    const WIFI_SWITCH_ON   = 1;
    const WIFI_SWITCH_OFF  = 0;
    const WIFI_SWITCH_TEXT = [
        self::WIFI_SWITCH_ON  => "开启",
        self::WIFI_SWITCH_OFF => "关闭"
    ];

    const STATUS_0    = 0;
    const STATUS_1    = 1;
    const STATUS_2    = 2;
    const STATUS_3    = 3;
    const STATUS_4    = 4;
    const STATUS_5    = 5;
    const STATUS_TEXT = [
        self::STATUS_0 => "异常 [ 上传点位数据异常 ]",
        self::STATUS_1 => "起点",
        self::STATUS_2 => "移动",
        self::STATUS_3 => "停留",
        self::STATUS_4 => "异常 [ 点位上传超时 ]",
        self::STATUS_5 => "异常 [ 经纬度缺失 ]",
    ];

    const STATUS_SHOW_TEXT = [
        self::STATUS_0 => "异常 [ 上传点位数据异常 ]",
        self::STATUS_1 => "起点",
        self::STATUS_2 => "移动",
        self::STATUS_3 => "停留",
        self::STATUS_4 => "轨迹异常，他的网络异常，暂无数据",
        self::STATUS_5 => "轨迹异常，他关闭了定位或夸父运营，该时段无定位信息"
    ];

    const LOCATION_TYPE_0 = 0;
    const LOCATION_TYPE_1 = 1;
    const LOCATION_TYPE_2 = 2;
//    const LOCATION_TYPE_3  = 3;
    const LOCATION_TYPE_4 = 4;
    const LOCATION_TYPE_5 = 5;
    const LOCATION_TYPE_6 = 6;
//    const LOCATION_TYPE_7  = 7;
    const LOCATION_TYPE_8 = 8;
    const LOCATION_TYPE_9 = 9;
//    const LOCATION_TYPE_10 = 10;
    const LOCATION_TYPE_11   = 11;
    const LOCATION_TYPE_TEXT = [
        self::LOCATION_TYPE_0  => "定位失败",
        self::LOCATION_TYPE_1  => "gps定位结果",
        self::LOCATION_TYPE_2  => "前次定位结果",
//        self::LOCATION_TYPE_3 => "定位失败",
        self::LOCATION_TYPE_4  => "缓存定位结果",
        self::LOCATION_TYPE_5  => "wifi定位结果",
        self::LOCATION_TYPE_6  => "基站定位结果",
//        self::LOCATION_TYPE_7 => "",
        self::LOCATION_TYPE_8  => "离线定位结果",
        self::LOCATION_TYPE_9  => "最后位置缓存",
//        self::LOCATION_TYPE_10 => "",
        self::LOCATION_TYPE_11 => "模糊定位",
    ];

    /**
     * @param int $dailyGatherId
     * @param int $startTime
     * @param int $endTime
     * @return Builder[]|Collection
     */
    public static function getDailyTracePoint(int $dailyGatherId, int $startTime, int $endTime)
    {
        return self::query()
                   ->where("dailyGatherId", $dailyGatherId)
                   ->where("tracePointTime", ">=", $startTime)
                   ->where("tracePointTime", "<=", $endTime)
                   ->where("status", ">", AttendanceDailyPointTraceModel::STATUS_0)
                   ->orderBy("id")
                   ->get();
    }
}
